<template>
  <div class="heart-container">
    <div class="heart-box">
      <div class="heart" :class="slotClass" rel="like" @click="onClick"></div>
      <div class="likeCount">{{likes}}</div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'heart',
  props: {
    id: Number,
    likes: {
      type: Number,
      default: 0
    },
    liked: {
      type: Boolean,
      default: false
    },
    clickable: {
      type: Boolean,
      default: true
    }
  },

  data () {
    return {
      animal: false,
      activeClass: 'active',
      loading: false
    }
  },
  computed: {
    slotClass () {
      if (this.liked && this.activeClass) {
        return ['active']
      }
      if (!this.clickable) {
        return ''
      }
      return this.liked ? 'heartAnimation' : ''
    }
  },

  methods: {
    onClick () {
      this.activeClass = ''
      if (this.clickable) {
        this.$emit('change', this.id)
      }
    }
  }
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less" scoped>
.heart-container {
  p {
    font-family: "Microsoft YaHei", "Georgia", Times, Times New Roman, serif;
    font-size: 25px;
  }
}
.heart-box {
  height: 100px;
  width: 100px;
  position: relative;
}

.heart {
  background: url(/static/images/heart_animation.png);
  background-position: left;
  background-repeat: no-repeat;
  height: 100%;
  width: 100%;
  cursor: pointer;
  background-size: 2900%;
}

.heart.active {
  background-position: right;
}

@-webkit-keyframes heartBlast {
  0% {
    background-position: left;
  }

  100% {
    background-position: right;
  }
}

@keyframes heartBlast {
  0% {
    background-position: left;
  }

  100% {
    background-position: right;
  }
}
.likeCount {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 30%;
  font-size: 13px;
  width: 100%;
  text-align: center;
  color: rgba(255, 255, 255, 0.8);
}
.heartAnimation {
  display: inline-block;
  -webkit-animation-name: heartBlast;
  animation-name: heartBlast;
  -webkit-animation-duration: 0.8s;
  animation-duration: 0.8s;
  -webkit-animation-iteration-count: 1;
  animation-iteration-count: 1;
  -webkit-animation-timing-function: steps(28);
  animation-timing-function: steps(28);
  background-position: right;
}
</style>
